package Test.stream流测试;

import Test.Test02.Student;

import java.util.*;

/**
 * @Author kirito
 * @Date 2023/12/13 19:01
 * @PackageName:Test.stream流测试
 * @ClassName: a
 * @Description:
 * @Version 1.0
 */
public class StreamDemo8 {
    public static void main(String[] args) {
        /**
         * 查找最大最小值
         */

        List<Student> list = new ArrayList<>();
        list.add(new Student("马化腾",25));
        list.add(new Student("李彦宏",27));
        list.add(new Student("雷军",35));
        list.add(new Student("马云",55));

        //  查找年龄最大的人
        Optional<Student> max = list.stream().max((e1, e2) -> e1.getAge() - e2.getAge());
//        Optional<Student> max = list.stream().max(Comparator.comparingInt(Student::getAge));
        // 返回马云，55岁年龄最大
        System.out.println(max.get());

        System.out.println("--------");


    }
}


